package com.netty.chapter02;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.NettyRuntime;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class TestEventLoop {
    public static void main(String[] args) {
        EventLoopGroup group=new NioEventLoopGroup(2);
        // 获取下一个循环事件
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(NettyRuntime.availableProcessors());
        // 执行普通任务
        group.next().submit(()->{
            try {
                Thread.sleep(1000);
                log.info("执行普通任务");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        // 执行定时任务
        group.next().scheduleAtFixedRate(()->{
                log.info("执行定时任务");
        },2,1, TimeUnit.SECONDS);
        log.info("执行主函数");
    }
}
